/**********************************************************************
 * SailmiPIM - modular cross-platform feature Personal Information Manager Tools.
 * Copyright(C) 2006-2014  Georg Rudoy
 *
 * Distributed under the Boost Software License, Version 1.0.
 *(See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
 **********************************************************************/

#ifndef COREINSTANCEOBJECT_H
#define COREINSTANCEOBJECT_H
#include <QObject>
#include "sailmipim/iinfo.h"
#include "sailmipim/ihavesettings.h"
#include "sailmipim/ihavetabs.h"
#include "sailmipim/ipluginready.h"
#include "sailmipim/ihaveshortcuts.h"
#include "util/core/logger.h"
class IShortcutProxy;

namespace SailmiPIM
{
	class SettingsTab;
	class CorePlugin2Manager;
	class ShortcutManager;

	namespace Util
	{
		class ShortcutManager;
	}

	class CoreInstanceObject : public QObject
							 , public IInfo
							 , public IHaveSettings
							 , public IHaveTabs
							 , public IHaveShortcuts
							 , public IPluginReady
	{
		Q_OBJECT
		Q_INTERFACES(IInfo IHaveSettings IHaveTabs IHaveShortcuts IPluginReady)

		Util::XmlSettingsDialog_ptr XmlSettingsDialog_;
		TabClasses_t Classes_;
        Logger log;

		SettingsTab *SettingsTab_ = nullptr;

		CorePlugin2Manager *CorePlugin2Manager_;

		ShortcutManager *ShortcutManager_;

		Util::ShortcutManager *CoreShortcutManager_;

		ICoreProxy_ptr Proxy_;
	public:
		CoreInstanceObject(QObject* = 0);

		// IInfo
		void SetProxy(ICoreProxy_ptr);
		const ICoreProxy_ptr& GetProxy();
		void SetPluginInstance(QObject*);

		void Init(ICoreProxy_ptr);
		void SecondInit();
		void Release();
        bool IsCore() const;
		QByteArray GetUniqueID() const;
		QString GetName() const;
		QString GetInfo() const;
		QIcon GetIcon() const;

		// IHaveSettings
		Util::XmlSettingsDialog_ptr GetSettingsDialog() const;

		// IHaveTabs
		TabClasses_t GetTabClasses() const;
        void TabOpenRequested(const QByteArray&,const QMap<QString,QString>& args);

		// IHaveShortcuts
		QMap<QByteArray, ActionInfo> GetActionInfo() const;
		void SetShortcut(const QByteArray& id, const QKeySequences_t& sequences);

		// IPluginReady
		QSet<QByteArray> GetExpectedPluginClasses() const;
		void AddPlugin(QObject*);

		CorePlugin2Manager* GetCorePluginManager() const;

		SettingsTab* GetSettingsTab();

		IShortcutProxy* GetShortcutProxy() const;
		ShortcutManager* GetShortcutManager() const;
		Util::ShortcutManager* GetCoreShortcutManager() const;
	private:
		void BuildNewTabModel();
		void LazyInitSettingsTab();
	private slots:
		void handleSettingsButton(const QString&);
		void updateIconSet();
		void updateColorTheme();
#ifdef STRICT_LICENSING
		void notifyLicensing();
#endif
	signals:
		void gotEntity(const SailmiPIM::Entity&);
	};
}

#endif
